#!/usr/bin/env python
# -*- coding:utf-8 -*-
from django.template import Library
from django.urls import reverse
register = Library()
from web import models
# 传入一个模板
@register.inclusion_tag('web/inclusion/show_all_project_list.html')
# 方法名称为最终html使用的名字
def all_project_list(request):
    project_list_my = models.Project.objects.filter(creator=request.tracer.user)
    project_list_join = models.ProjectUser.objects.filter(user=request.tracer.user)
    context = {
        'my': project_list_my,
        'join': project_list_join,
        'request':request
    }
    # 返回一个字典
    return context

@register.inclusion_tag('web/inclusion/show_menu.html')
def manage_menu_list(request):
    data_list = [
        {'title':'概览','url':reverse('web:dashboard',kwargs={'project_id':request.tracer.project.id})},
        {'title':'问题','url':reverse('web:issues',kwargs={'project_id':request.tracer.project.id})},
        {'title':'统计','url':reverse('web:statistics',kwargs={'project_id':request.tracer.project.id})},
        {'title':'文件','url':reverse('web:files',kwargs={'project_id':request.tracer.project.id})},
        {'title':'wiki','url':reverse('web:wiki',kwargs={'project_id':request.tracer.project.id})},
        {'title':'配置','url':reverse('web:setting',kwargs={'project_id':request.tracer.project.id})},
    ]
    
    for data in data_list:
        if request.path_info.startswith(data['url']):
            data['class']='active'
            
    context = {
        'data_list':data_list
    }
    return context
    